package cn.virens.common.simple;

import cn.hutool.core.collection.CollUtil;
import io.mybatis.provider.EntityColumn;
import io.mybatis.provider.EntityColumnFactory;
import io.mybatis.provider.EntityField;
import io.mybatis.provider.EntityTable;

import java.util.List;
import java.util.Optional;

public class MysqlEntityColumnFactory implements EntityColumnFactory {

    @Override
    public Optional<List<EntityColumn>> createEntityColumn(EntityTable entityTable, EntityField field, Chain chain) {
        return chain.createEntityColumn(entityTable, field).map(ecs -> CollUtil.map(ecs, ec -> {
            ec.column("`" + ec.column() + "`");

            return ec;
        }, true));
    }

    @Override
    public int getOrder() {
        return 1;
    }

}
